package cn.tedu.hotel.serve.service.impl;

import cn.tedu.hotel.serve.mapper.SecondaryConsultMapper;
import cn.tedu.hotel.serve.pojo.entity.secondary.Consult;
import cn.tedu.hotel.serve.service.ISecondaryConsultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class SecondaryConsultServiceImpl implements ISecondaryConsultService {

    @Autowired
    private SecondaryConsultMapper secondaryConsultMapper;

    @Override
    public void addNew(Consult consult) {
        secondaryConsultMapper.insert(consult);
        log.debug("咨询数据插入完成");
    }

    @Override
    public void delete(Long id) {
        secondaryConsultMapper.deleteById(id);
        log.debug("咨询已删除完毕，ID：{}", id);
    }

    @Override
    public void updateInfoById(Long id, Consult consult) {
        consult.setId(id);
        secondaryConsultMapper.update(consult);
        log.debug("咨询已更新完毕，ID：{}", id);
    }

    @Override
    public Consult getStandardById(Long id) {
        log.debug("开始处理【根据ID查询咨询详情】的业务，参数：{}", id);
        return secondaryConsultMapper.getStandardById(id);
    }

    @Override
    public List<Consult> list() {
        log.debug("开始处理【查询咨询列表】的业务，无参数");
        return secondaryConsultMapper.list();
    }
    @Override
    public void updateViewCountById(Long id){
        Consult consult =secondaryConsultMapper.getStandardById(id);
        if (consult.getView()==null){
            consult.setView(0);
            secondaryConsultMapper.update(consult);
        }
        secondaryConsultMapper.updateViewCountById(id);
        log.debug("咨询浏览量已更新");
    }
}
